import baseData from './components/base-data'
import transferData from './components/transfer-data'
import propertyOwnership from './components/property-ownership'
import uploadMedia from '@/components/upload-media'
import {save, get, edit,getLandInfo} from '@/views/property-info-sys/property-manage/api/room'
import BaseLoad from '@/assets/vue-mixin/BaseLoad'

export default {
    name: 'resource-manage-edit',
    mixins: [BaseLoad],
    components: {baseData, propertyOwnership, transferData, uploadMedia},
    created() {
        this.landUses = this.getDict('land_uses')
        let param = this.$route.query.id
        this.projectId = this.$route.query.projectId
        if(param){
            this.loadAction('数据加载中')
            this.id = param
            //初始化数据
            get(this.id).then(rep => {
                let repData = rep.data.data
                this.roomInfo = repData.roomInfo
                this.propertyInfo = repData.propertyInfo
                this.propertyCard = repData.assetRegistration
                this.$refs.baseData.updateInit(this.roomInfo)
                this.$refs.belong.initOwner(this.propertyInfo, this.propertyCard, this.roomInfo.propertyOwnership)
                this.$refs.transfer.initTransfer(this.roomInfo)
                //
                this.$refs.propertyFiles.getFiles(this.id)
                this.loadClose()
            }).catch(e => {
                this.loadClose()
            })
        }
        this.handleGetLandInfo(1)
    },
    data() {
        return {
            id: '',
            projectId: '',
            isAdd: true,
            uploadFileList: [],
            modelType: 'property',
            fileUploadUrl: '/admin/sys-file/upLodeFileEdit',
            //文件上传失败标识，true失败 false成功
            uploadError: false,
            tableData: [],
            roomInfo: {},
            propertyInfo: {},
            propertyCard: {},
            landInfo: {
                address: '',
                addressInfo: '',
                landContractNum: '',
                landId: '',
                landUse: '',
                parcelArea: '',
                parcelNum: '',
                remarks: ''
            },
            landUses: []
        }
    },
    methods: {
        closeNowRouter() {
            //关闭当前新增页，暂时没找到好办法
            this.$store.commit("delHistoryRoute", this.$route.fullPath);
            //跳转
            this.$router.push("/property-info-sys/property-manage");
        },
        // hxf-1010-根据id获取土地信息
        handleGetLandInfo(type) {
            getLandInfo(type,this.projectId).then(res => {
                if (res.data.code === 0 && res.data.data !== null) {
                    this.landInfo = res.data.data
                }
            })
        },
        // hxf-1010-回显时对应value显示label
        getCardTypeValue(num, sum){
            let arr = sum.filter(e=>e.value === num)
            if (arr.length > 0) {
                return arr[0].label
            } else {
                return num
            }
        }
    }
}
